#!/bin/bash
#
# redis - this scripts start and stop the redis daemon
#
# chkconfig: 345 96 86
# description: redis is a key-value storaged system 
# processname: redis
#
# Version      : v0.0.1
# Author       : rengyi yan
# Date         : 2015-08-06

prog="redis-server"
exec="/usr/sbin/$prog"
pidfile="/var/run/redis.pid"
configfile="/etc/redis/redis.conf"
lockfile="/var/lock/subsys/redis"

RETVAL=0

#Source function library
. /etc/init.d/functions

#Source networking configuration
. /etc/sysconfig/network

#Check network is up or down,if down then scripts exit 
[ $NETWORKING = 'no' ] && exit -1

#Check exec is an executable file,if not then scripts exit
[ -x $exec ] || exit -1

#Starting redis daemon functions

start() {

	 if [ -e $pidfile ];then
	    echo "$prog is already running..."
	    exit 1
	 fi

         echo -n $"Starting $prog:"
	 daemon $exec  $configfile
	
	 RETVAL=$?
         echo 
	 [ $RETVAL = 0 ] && touch $lockfile
	 return $RETVAL

}

stop() { 
	 echo -n $"Stopping $prog..."
	 killproc $exec
	
	 RETVAL=$?
	 echo
	 [ $RETVAL = 0 ] && rm -f $lockfile $pidfile
	 return $RETVAL
}

reload() {
 	  echo -n $"Reloading $prog..."
	  killproc $exec -HUP
	 
	  RETVAL=$?
	  echo
}

# See how we were called 
case "$1" in
	start)
	    start
	    ;;
	stop)
	    stop
	    ;;
	reload)
	    reload
	    ;;
	restart)
	    stop
	    start
	    ;;
	status)
	    status $prog
	    RETVAL=$?
	    ;;
	*)
	    echo $"Usage:$prog {start|stop|reload|restart|status|help}"
	    exit 1
esac

exit $RETVAL
